package com.tensquare.qa.controller;

import com.tensquare.entity.Result;
import com.tensquare.entity.StatusCode;
import com.tensquare.qa.client.LabelClient;
import com.tensquare.qa.pojo.Problem;
import com.tensquare.qa.service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by WF on 2020/12/15 15:56
 */
@RestController
@RequestMapping("problem")
public class ProblemController {
    @Autowired
    private LabelClient labelClient;
    @Autowired
    private ProblemService problemService;

    //1.查询最新问题列表
    @GetMapping("/newlist/{labelid}/{page}/{size}")
    public Result newlist(@PathVariable Integer labelid,@PathVariable Integer page,@PathVariable Integer size){
        //1.1)查询得到最新问题列表
        List<Problem> problems = problemService.newlist(labelid,page,size);
        //1.2)返回
        return new Result(true, StatusCode.OK,"查询最新问题列表成功！",problems);
    }

    //2.热门问答列表
    @GetMapping("hotlist/{labelid}/{page}/{size}")
    public Result hotlist(@PathVariable Integer labelid,@PathVariable Integer page,@PathVariable Integer size){
        //2.1)查询热门问题
        List<Problem> problems = problemService.hotlist(labelid,page,size);
        //2.2)返回
        return new Result(true, StatusCode.OK,"查询热门问题列表成功！",problems);
    }

    //3.查询base微服务下的label表
    @GetMapping("/label/{id}")
    public Result findById(@PathVariable String id){
        //3.1)访问base服务的label控制器下的方法
        return labelClient.findById(id);
    }
}
